package com.situ.controller;

import com.situ.domain.dto.OrderPageQueryDTO;
import com.situ.domain.entity.TOrder;
import com.situ.domain.vo.BasePageQueryVO;
import com.situ.domain.vo.OrderReportVO;
import com.situ.domain.vo.UserInfoVO;
import com.situ.ex.ParamErrorException;
import com.situ.service.OrderService;
import com.situ.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "订单接口")
public class OrderController {

    private final OrderService orderService;

    @Operation(summary = "查询订单列表")
    @GetMapping("getOrderList")
    public Result<BasePageQueryVO<TOrder>> getOrderList(@ParameterObject OrderPageQueryDTO pageQueryDTO) {
        log.info("查询订单列表接口:{}",pageQueryDTO);
        BasePageQueryVO<TOrder> pageQueryVO = orderService.getOrderList(pageQueryDTO);
        return Result.success(200, "查询成功", pageQueryVO);
    }

    @GetMapping("getUserByOrder")
    @Operation(summary = "根据订单ID查询用户")
    public Result<UserInfoVO> getUserByOrder (String oid) {
        UserInfoVO user = orderService.getUserByOrder(oid);
        return Result.success(200, "查询成功", user);
    }


    @DeleteMapping("/deleteOrderById")
    @Operation(summary = "根据订单id删除订单")
    public Result deleteOrdrById (String oid) {
        if (oid == null || "".equals(oid)) {
            throw new ParamErrorException();
        }
        log.info("删除订单接口:{}",oid);
        orderService.deleteOrdrById(oid);
        return Result.ok("删除成功");
    }


    @GetMapping("/getOrderReport")
    @Operation(summary = "查询热门商品的统计信息")
    public Result<OrderReportVO> getOrderReport () {
        log.info("查询订单报表");
        OrderReportVO orderReportVO = orderService.getOrderReport();
        return Result.success(200, "查询成功", orderReportVO);
    }

}
